import java.util.Scanner;
public class Solution {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] prices = new int[n];
        for(int i = 0; i < n; i++) {
            prices[i] = in.nextInt();
        }
        int money = max_money(prices);
        System.out.println(money);
    }


    /*买卖股票，多次买入卖出*/
    private static int max_money(int[] prices){
        int n = prices.length;
        //i个位置时，处于买入状态，利润最大
        int[] f = new int[n];
        //i个位置时，处于卖出状态时，利润最大
        int[] g = new int[n];
        f[0] = -prices[0];
        g[0] = 0;
        int max = 0;
        for(int i = 1; i < n; i++) {
            //f[i]这一天为买入状态，前一天可能卖出，可能买入
            f[i] = Math.max(g[i-1] - prices[i],f[i-1]);
            //g[i]这一天为卖出状态，前一天可能买入，可能卖出
            g[i] = Math.max(f[i-1] + prices[i],g[i-1]);
            max =Math.max(0, (Math.max(f[i],g[i])));
        }
        return max;
    }
}
